<?php
class sis_setup_variabel_model extends MY_Model {
	var $model = 'sis_setup_variabel';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	A.*
					FROM	SIS_SETUP_VARIABEL A
					WHERE	(UPPER(NVL(ID_VARIABEL,'')) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(NAMA_VARIABEL,'')) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(KETERANGAN,'')) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'ID_VARIABEL' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetDetail($param=array())
	{
		
		/*$ls_sql	= "	SELECT	A.*
					FROM	SIS_SETUP_VARIABEL A
					ORDER BY ID_VARIABEL";*/
		$this->db->from('SIS_SETUP_VARIABEL');
		if(count($param) > 0){
			$this->db->where_in('ID_VARIABEL', $param);
		}
		$this->db->order_by('ID_VARIABEL');
		$result = $this->db->get();
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return NULL;
		}
	}
	
	function Add($arr_data){
		$this->db->insert('SIS_SETUP_VARIABEL', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('SIS_SETUP_VARIABEL', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_idvariabel){
		$result = $this->db->get_where('SIS_SETUP_VARIABEL', array('ID_VARIABEL' => $as_idvariabel));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_idvariabel)
	{
		$result = $this->db->get_where('SIS_SETUP_VARIABEL', array('ID_VARIABEL' => $as_idvariabel));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM SIS_SETUP_PARAMETER WHERE ID_VARIABEL = '".$arr_rule['ID_VARIABEL']."'"))>0)
			{
				return $this->error_delete.' [id: '.$arr_rule['ID_VARIABEL']."]<br />";
			}else{
				$this->db->delete('SIS_SETUP_VARIABEL', array('ID_VARIABEL' => $arr_rule['ID_VARIABEL']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>